import 'package:flutter/material.dart';
import 'package:flutter_jd/pages/tabbar/cart/controller.dart';
import 'package:flutter_jd/ui/pages/cart/bottom_wrap.dart';
import 'package:flutter_jd/ui/pages/cart/goods_list.dart';
import 'package:flutter_jd/ui/pages/cart/shop_wrap.dart';
import 'package:flutter_jd/ui/widgets/refresh/pull_refresh.dart';
import 'package:flutter_jd/ui/widgets/body/top_bar.dart';
import 'package:get/route_manager.dart';
import 'package:get/get.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

// 购物车
class Cart extends GetView<CartController> {
  @override
  Widget build(BuildContext context) {
    Get.put(CartController());
    return new Scaffold(
      appBar: TopBar(
        title: '购物车',
        titleStyle: TextStyle(
          color: Colors.black,
          fontSize: 17.sp,
        ),
        backgroundColor: Color(0xFFF5F5F5),
      ),
      body: GetBuilder<CartController>(
        init: CartController(),
        builder: (controller) {
          return Container(
            color: Color(0xFFF5F5F5),
            child: Column(
              children: [
                _buildBody(),
                CartBottomWrap(),
              ],
            ),
          );
        },
      ),
    );
  }

  // 主体
  Widget _buildBody() {
    return Expanded(
      child: PullRefresh(
        refreshController: controller.refreshController,
        onRefresh: controller.onRefresh,
        onLoading: controller.onLoading,
        child: ListView(
          children: List.generate(
            controller.productList.length,
            (index) => Container(
              margin: EdgeInsets.only(
                top: index == 0 ? 10.h : 0,
                bottom: 10.h,
              ),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  CartShopWrap(index),
                  CartGoodsList(index),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
